package cn.nai.DemoRan.demo01;

import java.util.Scanner;
import java.util.stream.IntStream;

public class SortArray {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);

        System.out.println("数组长度：");
        int num = input.nextInt();

        int[] arr = new int[num];
        System.out.println("请输入数组内的元素：");
        for (int i = 0; i < arr.length; i++) arr[i] = input.nextInt();
        for(int i = arr.length - 1; i >= 0; i--) {
            int bound = arr.length - 1;
            for (int j = 0; j < bound; j++) {
                if (arr[j] > arr[j + 1]) {
                    int temp = arr[j];
                    arr[j] = arr[j + 1];//交换位置
                    arr[j + 1] = temp;
                }
            }
        }
        for (int j : arr) {
            System.out.println(j);
        }
    }
}
